<?php
/**
 * Created by PhpStorm.
 * User: THINK
 * Date: 2017/8/26
 * Time: 10:09
 */
namespace Home\Controller;

use Think\Controller;

class LoginController extends Controller
{
    public function index(){
        $indexs = M('announce');
        $lists = $indexs->order('posttime desc')->limit(0,1)->select();
        $this->assign('lists',$lists);
        $this->display();
    }
    public function logins(){
        $login =M('member');
        $s = I('post.');
        $verify = new \Think\Verify();
        if($verify->check($s['vcode'])){
            $s['password']  = md5($s['password']);
            $list = $login->where('email="'.$s['email'].'" and password="'.$s['password'].'"')->select();
            if (count($list)>0){
                session('name',$list['0']['nickname']);
                $this->success('登录成功');
                $list['logintime'] = time();
                $list['loginip'] = get_client_ip();
                $login->where('email="'.$s['email'].'"')->save($list);
                $login->where('email="'.$s['email'].'"')->setInc('loginnum');
                $this->redirect('home/member/index');
            }else{

                echo "<script>alert('登录失败,邮箱或密码错误');history.back();</script>";
            }
        }else{
            echo "<script>alert('验证码错误');history.back();</script>";
        }
    }
}